package com.andaily.domain.thing.handler;

import com.andaily.domain.thing.Thing;
import com.andaily.domain.user.User;
import com.andaily.service.MailService;
import com.andaily.web.context.BeanProvider;

import java.util.Date;
import java.util.List;

/**
 * Date: 13-7-20
 *
 * @author Shengzhao Li
 */
public class AutoStartThingMailHandler {

    public static String subject = "事情自动开始提醒 -- Andaily";
    private transient MailService mailService = BeanProvider.getBean(MailService.class);

    private final User user;
    private final List<Thing> things;
    private final Date startDate;

    public AutoStartThingMailHandler(User user, List<Thing> things, Date startDate) {
        this.user = user;
        this.things = things;
        this.startDate = startDate;
    }

    public void handle() {
        AutoStartThingMailRender autoStartThingMailRender = new AutoStartThingMailRender(subject, startDate, things);
        String content = autoStartThingMailRender.render();
        String email = user.email();
        mailService.sendSimpleMail(subject, email, content);
    }

}
